package io.geekidea.springbootplus.system.service.impl;

import io.geekidea.springbootplus.system.entity.AdminSchool;
import io.geekidea.springbootplus.system.mapper.AdminSchoolMapper;
import io.geekidea.springbootplus.system.service.AdminSchoolService;
import io.geekidea.springbootplus.system.param.AdminSchoolPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *  服务实现类
 *
 * @author miko
 * @since 2020-10-10
 */
@Slf4j
@Service
public class AdminSchoolServiceImpl extends BaseServiceImpl<AdminSchoolMapper, AdminSchool> implements AdminSchoolService {

    @Autowired
    private AdminSchoolMapper adminSchoolMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveAdminSchool(AdminSchool adminSchool) throws Exception {
        return super.save(adminSchool);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateAdminSchool(AdminSchool adminSchool) throws Exception {
        return super.updateById(adminSchool);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteAdminSchool(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<AdminSchool> getAdminSchoolPageList(AdminSchoolPageParam adminSchoolPageParam) throws Exception {
        Page<AdminSchool> page = new PageInfo<>(adminSchoolPageParam, OrderItem.desc(getLambdaColumn(AdminSchool::getCreateTime)));
        LambdaQueryWrapper<AdminSchool> wrapper = new LambdaQueryWrapper<>();
        IPage<AdminSchool> iPage = adminSchoolMapper.selectPage(page, wrapper);
        return new Paging<AdminSchool>(iPage);
    }

}
